num = input()

if len(num) != 4 or not num.isdigit():
    print(0)

else:
    num = int(num)
    for i in range(4, 1, -1):
        for j in range(0, 4 - i + 1):
            curr_num = int(str(num)[j:j + i])
            is_prime = True
            for k in range(2, int(curr_num ** 0.5) + 1):
                if curr_num % k == 0:
                    is_prime = False
                    break
            if is_prime:
                print(curr_num)
                exit()
    print(0)
